<div style="margin: 5px;">
    <div class="layui-btn-group userTable">
        <button class="layui-btn" data-type="addSort">添加分类</button>
    </div>
    <table id="classify-table" lay-filter="classify-table-filter"></table>
</div>
<script type="text/html" id="classifyBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script>
    layui.use(['table', 'form'], function () {
        var table = layui.table;
        //-------会员管理表格s--------
        var user = table.render({
            elem: '#classify-table'
            , height: 'full-180'
            , url: '/admin/classify/ajax'
            , page: true
            , cols: [[
                 {field: 'id', title: 'ID',align:'center'}
                ,{field: 'name', title: '分类名',align:'center'}
                , {field: '', title: '操作', toolbar: '#classifyBar',align:'center'}
            ]]
        });
        table.on('tool(classify-table-filter)', function (obj) {
            let data = obj.data;
            if (obj.event == 'del') {

                layer.confirm('确认要删除<span style="color:green">' + data.name + '</span>分类?', function (index) {
                    $.ajax({
                        type: 'post'
                        , url: '/admin/classify/dell'
                        , dataType: 'json'
                        , data: {id: data.id}
                        , success: function (obj1) {
                            if (obj1.code == 1) {
                                obj.del();
                            }
                            layer.alert(obj1.msg);
                        }
                    });
                    layer.close(index);
                });
            }
            });
        var $ = layui.$, active = {
            addSort: function () { //获取选中数据
                layer.prompt({title:'新增分类名'},function(value, index, elem){
                    $.ajax({
                        type: 'post'
                        , url: '/admin/classify/add'
                        , dataType: 'json'
                        , data: {name: value}
                        , success: function (obj1) {
                            layer.alert(obj1.msg);
                        }
                    });
                    layer.close(index);
                });
            }
        };
        $('.userTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //-------会员管理表格e--------



    });
</script>

